<template>
  <div>
    <el-row :gutter="10">
      <el-col :span="6">
        <el-card>用户人数：{{numberList.studentNumber}}</el-card>
      </el-col>
      <el-col :span="6">
        <el-card>今日已填：{{numberList.dayRecord}}</el-card>
      </el-col>
      <el-col :span="6">
        <el-card>今日风险人数：{{numberList.dangerNumber}}</el-card>
      </el-col>
      <el-col :span="6">
        <el-card>管理员人数：{{numberList.adminNumber}}</el-card>
      </el-col>
    </el-row>
    <el-row style="margin-top: 10px" :gutter="10">
      <el-col :span="12">
        <el-card>
          <div id="goodsChart" style="width: 550px; height: 500px"></div>
        </el-card>
      </el-col>
      <el-col :span="12">
        <el-card>
          <div id="contractChart" style="width: 550px; height: 500px;"></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {getGoodsData,getContractData,getNumberData} from '@/api/common'
  export default {
    name: "Main",
    data(){
      return {
        numberList: {
          studentNumber: 0,
          dayRecord: 0,
          dangerNumber: 0,
          adminNumber: 0
        },
        goodsChartOption: {
            title: { text: '用户数报表' },
            tooltip: {},
            xAxis: {
              data: []
            },
            yAxis: {},
            series: [{
                name: '人数',
                type: 'bar',
                data: [1,2,3,4,5]
            }]
        },
        contractChartOption: {
            title: { text: '风险数报表' },
            tooltip: {},
            xAxis: {
              data: []
            },
            yAxis: {},
            series: [{
                name: '风险人数',
                type: 'bar',
                data: [1,2,3,4,5]
            }]
        }
      }
    },
    methods: {
			drawLine(){
        // 基于准备好的dom，初始化echarts实例
        let goodsChart = this.$echarts.init(document.getElementById('goodsChart'))
        // 绘制图表
        goodsChart.setOption(this.goodsChartOption);
      },
      drawLine2(){
        let contractChart = this.$echarts.init(document.getElementById('contractChart'))
        // 绘制图表
        contractChart.setOption(this.contractChartOption);
      },
      getGoodsStatisticsData(){
        getGoodsData().then(res => {
          this.goodsChartOption.xAxis.data = res.data.goodsNameList
          this.goodsChartOption.series[0].data = res.data.goodsSaleNumberList
          this.drawLine()
        })
      },
      getContractStatisticsData(){
        getContractData().then(res => {
          this.contractChartOption.xAxis.data = res.data.contractNameList
          this.contractChartOption.series[0].data = res.data.contractTotalCostList
          this.drawLine2()
        })
      }
    },
    created(){
      getNumberData().then(res => {
        this.numberList = res.data
      })
    },
    mounted(){
      this.drawLine();
      this.drawLine2();
    }
  }
</script>

<style scoped>

</style>
